﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using RayDen.RayEngine;
using RayDen.RayEngine.Core;
using RayDen.RayEngine.Core.Devices;
using RayDen.RayEngine.Core.Interface;
using RayDen.RayEngine.Core.Threads;
using RayDen.RayEngine.Managers;
using RayDen.RayEngine.Samplers;
using RayEngine.Spectral.Engine;
using RayEngine.Spectral.Engine.Imaging;

namespace RayEngine.Spectral
{
    [RenderingEngine(EngineType = RenderingEngines.External)]
    public class SpectralRenderingEngine : BaseRenderingEngine
    {
        private IImageFilm film;

        private SceneManager sceneManager;
        

        public SpectralRenderingEngine(RayEngineScene scene) : base(scene)
        {
            sceneManager = new SceneManager(scene);
            sceneManager.Build();

            new HitManager(sceneManager);
        }

        public override RenderThread CreateRenderThread(int threadIndex, IntersectionEngine intersectionDevice, RayEngineScene scene, 
            IImageFilm flm,IFrameManager manager, SamplingContext samplingContext)
        {
            if (this.film == null)
                film = flm;
            return new SpectralRenderThread(threadIndex, intersectionDevice, scene, samplingContext.LowLatency, this.film, samplingContext, manager,sceneManager);
        }

        public override ISampler CreateSampler(int width, int height, int maxPathDepth, int threadIndex, int screenStartLine, int windowHeight)
        {
            return SamplerFactory.Instance.CreateSampler(width, height, maxPathDepth, screenStartLine, LowLatencySampling,
                                                 threadIndex, windowHeight);
        }

        public override IImageFilm CreateFilm(int width, int height)
        {
            throw new NotImplementedException();
        }
    }
}
